home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_emacs.idb / usr / freeware / share / emacs / 19.34 / lisp / texinfo.el.z / texinfo.el
Encoding:
Text File  |  1998-10-28  |  30.5 KB  |  820 lines

  1. ;;; texinfo.el --- major mode for editing Texinfo files
  2.  
  3. ;; Copyright (C) 1985, 1988, 1989, 1990, 1991, 1992, 1993 Free Software
  4. ;; Foundation, Inc.
  5.  
  6. ;; Author: Robert J. Chassell          
  7. ;; Maintainer: FSF
  8.  
  9. ;; This file is part of GNU Emacs.
  10.  
  11. ;; GNU Emacs is free software; you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ;; GNU General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  23. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26.  
  27. ;;; Autoloads:
  28.  
  29. (autoload 'makeinfo-region
  30.           "makeinfo"
  31.   "Make Info file from region of current Texinfo file, and switch to it.
  32.  
  33. This command does not offer the `next-error' feature since it would
  34. apply to a temporary file, not the original; use the `makeinfo-buffer'
  35. command to gain use of `next-error'."
  36.           t nil)
  37.  
  38. (autoload 'makeinfo-buffer
  39.           "makeinfo"
  40.   "Make Info file from current buffer.
  41.  
  42. Use the \\[next-error] command to move to the next error 
  43. \(if there are errors\)."
  44.           t nil)
  45.  
  46. (autoload 'kill-compilation
  47.           "compile"
  48.   "Kill the process made by the \\[compile] command."
  49.           t nil)
  50.  
  51. (autoload 'makeinfo-recenter-compilation-buffer
  52.           "makeinfo"
  53.   "Redisplay `*compilation*' buffer so most recent output can be seen.
  54. The last line of the buffer is displayed on
  55. line LINE of the window, or centered if LINE is nil."
  56.           t nil)
  57.  
  58. (autoload 'texinfo-make-menu
  59.           "texnfo-upd"
  60.   "Without any prefix argument, make or update a menu.
  61. Make the menu for the section enclosing the node found following point.
  62.  
  63. Non-nil argument (prefix, if interactive) means make or update menus
  64. for nodes within or part of the marked region.
  65.  
  66. Whenever a menu exists, and is being updated, the descriptions that
  67. are associated with node names in the pre-existing menu are
  68. incorporated into the new menu.  Otherwise, the nodes' section titles
  69. are inserted as descriptions."
  70.           t nil)
  71.  
  72. (autoload 'texinfo-all-menus-update
  73.           "texnfo-upd"
  74.   "Update every regular menu in a Texinfo file.
  75. Remove pre-existing master menu, if there is one.
  76.  
  77. If called with a non-nil argument, this function first updates all the
  78. nodes in the buffer before updating the menus."
  79.           t nil)
  80.  
  81. (autoload 'texinfo-master-menu
  82.           "texnfo-upd"
  83.   "Make a master menu for a whole Texinfo file.
  84. Non-nil argument (prefix, if interactive) means first update all
  85. existing nodes and menus.  Remove pre-existing master menu, if there is one.
  86.  
  87. This function creates a master menu that follows the top node.  The
  88. master menu includes every entry from all the other menus.  It
  89. replaces any existing ordinary menu that follows the top node.
  90.  
  91. If called with a non-nil argument, this function first updates all the
  92. menus in the buffer (incorporating descriptions from pre-existing
  93. menus) before it constructs the master menu.
  94.  
  95. The function removes the detailed part of an already existing master
  96. menu.  This action depends on the pre-existing master menu using the
  97. standard `texinfo-master-menu-header'.
  98.  
  99. The master menu has the following format, which is adapted from the
  100. recommendation in the Texinfo Manual:
  101.  
  102.    * The first part contains the major nodes in the Texinfo file: the
  103.      nodes for the chapters, chapter-like sections, and the major
  104.      appendices.  This includes the indices, so long as they are in
  105.      chapter-like sections, such as unnumbered sections.
  106.  
  107.    * The second and subsequent parts contain a listing of the other,
  108.      lower level menus, in order.  This way, an inquirer can go
  109.      directly to a particular node if he or she is searching for
  110.      specific information.
  111.  
  112. Each of the menus in the detailed node listing is introduced by the
  113. title of the section containing the menu."
  114.           t nil)
  115.  
  116. (autoload 'texinfo-indent-menu-description
  117.           "texnfo-upd"
  118.   "Indent every description in menu following point to COLUMN.  
  119. Non-nil argument (prefix, if interactive) means indent every
  120. description in every menu in the region.  Does not indent second and
  121. subsequent lines of a multi-line description."
  122.           t nil)
  123.  
  124. (autoload 'texinfo-insert-node-lines
  125.           "texnfo-upd"
  126.   "Insert missing `@node' lines in region of Texinfo file.
  127. Non-nil argument (prefix, if interactive) means also to insert the
  128. section titles as node names; and also to insert the section titles as
  129. node names in pre-existing @node lines that lack names."
  130.           t nil)
  131.  
  132. (autoload 'texinfo-start-menu-description
  133.           "texnfo-upd"
  134.   "In this menu entry, insert the node's section title as a description. 
  135. Position point at beginning of description ready for editing.
  136. Do not insert a title if the line contains an existing description.
  137.  
  138. You will need to edit the inserted text since a useful description
  139. complements the node name rather than repeats it as a title does."
  140.           t nil)
  141.  
  142. (autoload 'texinfo-multiple-files-update
  143.           "texnfo-upd"
  144.   "Update first node pointers in each file included in OUTER-FILE;
  145. create or update main menu in the outer file that refers to such nodes. 
  146. This does not create or update menus or pointers within the included files.
  147.  
  148. With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
  149. insert a master menu in OUTER-FILE.  This does not create or update
  150. menus or pointers within the included files.
  151.  
  152. With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
  153. interactive), update all the menus and all the `Next', `Previous', and
  154. `Up' pointers of all the files included in OUTER-FILE before inserting
  155. a master menu in OUTER-FILE.
  156.  
  157. The command also updates the `Top' level node pointers of OUTER-FILE.
  158.  
  159. Notes: 
  160.  
  161.   * this command does NOT save any files--you must save the
  162.     outer file and any modified, included files.
  163.  
  164.   * except for the `Top' node, this command does NOT handle any
  165.     pre-existing nodes in the outer file; hence, indices must be
  166.     enclosed in an included file.
  167.  
  168. Requirements:
  169.  
  170.   * each of the included files must contain exactly one highest
  171.     hierarchical level node, 
  172.   * this highest node must be the first node in the included file,
  173.   * each highest hierarchical level node must be of the same type.
  174.  
  175. Thus, normally, each included file contains one, and only one,
  176. chapter."
  177.           t nil)
  178.  
  179.  
  180. ;;; Code:
  181.  
  182. ;;; Don't you dare insert any `require' calls at top level in this file--rms.
  183.  
  184. ;;; Syntax table
  185.  
  186. (defvar texinfo-mode-syntax-table nil)
  187.  
  188. (if texinfo-mode-syntax-table
  189.     nil
  190.   (setq texinfo-mode-syntax-table (make-syntax-table))
  191.   (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
  192.   (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
  193.   (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
  194.   (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
  195.   (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
  196.   (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
  197.   (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
  198.   (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
  199.   (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
  200.  
  201. ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
  202. ;; To override this example, set either `imenu-generic-expression'
  203. ;; or `imenu-create-index-function'.
  204. (defvar texinfo-imenu-generic-expression
  205.   '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
  206.     ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
  207.  
  208.   "Imenu generic expression for TexInfo mode.  See `imenu-generic-expression'.")
  209.  
  210. (defvar texinfo-font-lock-keywords
  211.   '(;; All but the first 2 had an OVERRIDE of t.
  212.     ;; It didn't seem to be any better, and it's slower--simon.
  213.     ("^\\(@c\\|@comment\\)\\>.*" . font-lock-comment-face)     ;comments
  214.     ;; Robert J. Chassell <bob@gnu.ai.mit.edu> says remove this line.
  215.     ;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  216.     ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face)    ;commands
  217.     ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t)     ;menu items
  218.     ("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face)
  219.     ("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face)
  220.     ("@\\(samp\\|code\\|var\\|math\\){\\([^}]+\\)"
  221.      2 font-lock-variable-name-face)
  222.     ("@\\(cite\\|xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-reference-face)
  223.     ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
  224.     )
  225.   "Additional expressions to highlight in TeXinfo mode.")
  226.  
  227. (defvar texinfo-section-list
  228.   '(("top" 1)
  229.     ("majorheading" 1)
  230.     ("chapter" 2)
  231.     ("unnumbered" 2)
  232.     ("appendix" 2)
  233.     ("chapheading" 2)
  234.     ("section" 3)
  235.     ("unnumberedsec" 3)
  236.     ("appendixsec" 3)
  237.     ("heading" 3)
  238.     ("subsection" 4)
  239.     ("unnumberedsubsec" 4)
  240.     ("appendixsubsec" 4)
  241.     ("subheading" 4)
  242.     ("subsubsection" 5)
  243.     ("unnumberedsubsubsec" 5)
  244.     ("appendixsubsubsec" 5)
  245.     ("subsubheading" 5))
  246.   "Alist of sectioning commands and their relative level.")
  247.  
  248. (defun texinfo-outline-level ()
  249.   ;; Calculate level of current texinfo outline heading.
  250.   (save-excursion
  251.     (if (bobp)
  252.     0
  253.       (forward-char 1)
  254.       (let* ((word (buffer-substring-no-properties 
  255.             (point) (progn (forward-word 1) (point))))
  256.          (entry (assoc word texinfo-section-list)))
  257.     (if entry
  258.         (nth 1 entry)
  259.       5)))))
  260.  
  261. ;;; Keybindings
  262. (defvar texinfo-mode-map nil)
  263.  
  264. ;;; Keys common both to Texinfo mode and to TeX shell.
  265.  
  266. (defun texinfo-define-common-keys (keymap)
  267.   "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
  268.   (define-key keymap "\C-c\C-t\C-k"    'tex-kill-job)
  269.   (define-key keymap "\C-c\C-t\C-x"    'texinfo-quit-job)
  270.   (define-key keymap "\C-c\C-t\C-l"    'tex-recenter-output-buffer)
  271.   (define-key keymap "\C-c\C-t\C-d"    'texinfo-delete-from-print-queue)
  272.   (define-key keymap "\C-c\C-t\C-q"    'tex-show-print-queue)
  273.   (define-key keymap "\C-c\C-t\C-p"    'texinfo-tex-print)
  274.   (define-key keymap "\C-c\C-t\C-i"    'texinfo-texindex)
  275.  
  276.   (define-key keymap "\C-c\C-t\C-r"    'texinfo-tex-region)
  277.   (define-key keymap "\C-c\C-t\C-b"    'texinfo-tex-buffer))
  278.  
  279. ;; Mode documentation displays commands in reverse order 
  280. ;; from how they are listed in the texinfo-mode-map.
  281.  
  282. (if texinfo-mode-map
  283.     nil
  284.   (setq texinfo-mode-map (make-sparse-keymap))
  285.  
  286.   ;; bindings for `texnfo-tex.el'
  287.   (texinfo-define-common-keys texinfo-mode-map)
  288.  
  289.   ;; bindings for `makeinfo.el'
  290.   (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
  291.   (define-key texinfo-mode-map "\C-c\C-m\C-l" 
  292.     'makeinfo-recenter-compilation-buffer)
  293.   (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
  294.   (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
  295.  
  296.   ; Bindings for texinfmt.el.
  297.   (define-key texinfo-mode-map "\C-c\C-e\C-r"    'texinfo-format-region)
  298.   (define-key texinfo-mode-map "\C-c\C-e\C-b"    'texinfo-format-buffer)
  299.  
  300.   ;; bindings for updating nodes and menus
  301.  
  302.   (define-key texinfo-mode-map "\C-c\C-um"   'texinfo-master-menu)
  303.  
  304.   (define-key texinfo-mode-map "\C-c\C-u\C-m"   'texinfo-make-menu)
  305.   (define-key texinfo-mode-map "\C-c\C-u\C-n"   'texinfo-update-node)
  306.   (define-key texinfo-mode-map "\C-c\C-u\C-e"   'texinfo-every-node-update)
  307.   (define-key texinfo-mode-map "\C-c\C-u\C-a"   'texinfo-all-menus-update)
  308.  
  309.   (define-key texinfo-mode-map "\C-c\C-s"     'texinfo-show-structure)
  310.  
  311.   (define-key texinfo-mode-map "\C-c}"        'up-list)
  312.   (define-key texinfo-mode-map "\C-c{"        'texinfo-insert-braces)
  313.  
  314.   ;; bindings for inserting strings
  315.  
  316.   (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
  317.  
  318.   (define-key texinfo-mode-map "\C-c\C-cv"    'texinfo-insert-@var)
  319.   (define-key texinfo-mode-map "\C-c\C-ct"    'texinfo-insert-@table)
  320.   (define-key texinfo-mode-map "\C-c\C-cs"    'texinfo-insert-@samp)
  321.   (define-key texinfo-mode-map "\C-c\C-co"    'texinfo-insert-@noindent)
  322.   (define-key texinfo-mode-map "\C-c\C-cn"    'texinfo-insert-@node)
  323.   (define-key texinfo-mode-map "\C-c\C-ck"    'texinfo-insert-@kbd)
  324.   (define-key texinfo-mode-map "\C-c\C-ci"    'texinfo-insert-@item)
  325.   (define-key texinfo-mode-map "\C-c\C-cf"    'texinfo-insert-@file)
  326.   (define-key texinfo-mode-map "\C-c\C-cx"    'texinfo-insert-@example)
  327.   (define-key texinfo-mode-map "\C-c\C-ce"    'texinfo-insert-@end)
  328.   (define-key texinfo-mode-map "\C-c\C-cd"    'texinfo-insert-@dfn)
  329.   (define-key texinfo-mode-map "\C-c\C-cc"    'texinfo-insert-@code))
  330.  
  331.  
  332. ;;; Texinfo mode
  333.  
  334. (defvar texinfo-chapter-level-regexp 
  335.   "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
  336.   "Regular expression matching Texinfo chapter-level headings.
  337. This does not match `@node' and does not match the `@top' command.")
  338.  
  339. ;;;###autoload
  340. (defun texinfo-mode ()
  341.   "Major mode for editing Texinfo files.
  342.  
  343.   It has these extra commands:
  344. \\{texinfo-mode-map}
  345.  
  346.   These are files that are used as input for TeX to make printed manuals
  347. and also to be turned into Info files with \\[makeinfo-buffer] or
  348. the `makeinfo' program.  These files must be written in a very restricted and
  349. modified version of TeX input format.
  350.  
  351.   Editing commands are like text-mode except that the syntax table is
  352. set up so expression commands skip Texinfo bracket groups.  To see
  353. what the Info version of a region of the Texinfo file will look like,
  354. use \\[makeinfo-region], which runs `makeinfo' on the current region.
  355.  
  356.   You can show the structure of a Texinfo file with \\[texinfo-show-structure].
  357. This command shows the structure of a Texinfo file by listing the
  358. lines with the @-sign commands for @chapter, @section, and the like.
  359. These lines are displayed in another window called the *Occur* window.
  360. In that window, you can position the cursor over one of the lines and
  361. use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
  362. in the Texinfo file.
  363.  
  364.   In addition, Texinfo mode provides commands that insert various
  365. frequently used @-sign commands into the buffer.  You can use these
  366. commands to save keystrokes.  And you can insert balanced braces with
  367. \\[texinfo-insert-braces] and later use the command \\[up-list] to
  368. move forward past the closing brace.
  369.  
  370. Also, Texinfo mode provides functions for automatically creating or
  371. updating menus and node pointers.  These functions
  372.  
  373.   * insert the `Next', `Previous' and `Up' pointers of a node,
  374.   * insert or update the menu for a section, and
  375.   * create a master menu for a Texinfo source file.
  376.  
  377. Here are the functions:
  378.  
  379.     texinfo-update-node                \\[texinfo-update-node]
  380.     texinfo-every-node-update          \\[texinfo-every-node-update]
  381.     texinfo-sequential-node-update 
  382.  
  383.     texinfo-make-menu                  \\[texinfo-make-menu]
  384.     texinfo-all-menus-update           \\[texinfo-all-menus-update]
  385.     texinfo-master-menu
  386.  
  387.     texinfo-indent-menu-description (column &optional region-p)
  388.  
  389. The `texinfo-column-for-description' variable specifies the column to
  390. which menu descriptions are indented. 
  391.  
  392. Passed an argument (a prefix argument, if interactive), the
  393. `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
  394. in the region.
  395.  
  396. To use the updating commands, you must structure your Texinfo file
  397. hierarchically, such that each `@node' line, with the exception of the
  398. Top node, is accompanied by some kind of section line, such as an
  399. `@chapter' or `@section' line.
  400.  
  401. If the file has a `top' node, it must be called `top' or `Top' and
  402. be the first node in the file.
  403.  
  404. Entering Texinfo mode calls the value of text-mode-hook, and then the
  405. value of texinfo-mode-hook."
  406.   (interactive)
  407.   (text-mode)
  408.   (setq mode-name "Texinfo")
  409.   (setq major-mode 'texinfo-mode)
  410.   (use-local-map texinfo-mode-map)
  411.   (set-syntax-table texinfo-mode-syntax-table)
  412.   (make-local-variable 'page-delimiter)
  413.   (setq page-delimiter 
  414.         (concat 
  415.          "^@node [ \t]*[Tt]op\\|^@\\(" 
  416.          texinfo-chapter-level-regexp 
  417.          "\\)"))
  418.   (make-local-variable 'require-final-newline)
  419.   (setq require-final-newline t)
  420.   (make-local-variable 'indent-tabs-mode)
  421.   (setq indent-tabs-mode nil)
  422.   (make-local-variable 'paragraph-separate)
  423.   (setq paragraph-separate (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
  424.   (make-local-variable 'paragraph-start)
  425.   (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
  426.   (make-local-variable 'fill-column)
  427.   (setq fill-column 72)
  428.   (make-local-variable 'comment-start)
  429.   (setq comment-start "@c ")
  430.   (make-local-variable 'comment-start-skip)
  431.   (setq comment-start-skip "@c +")
  432.   (make-local-variable 'words-include-escapes)
  433.   (setq words-include-escapes t)
  434.   (make-local-variable 'imenu-generic-expression)
  435.   (setq imenu-generic-expression texinfo-imenu-generic-expression)
  436.   (make-local-variable 'font-lock-defaults)
  437.   (setq font-lock-defaults '(texinfo-font-lock-keywords t))
  438.   (make-local-variable 'outline-regexp)
  439.   (setq outline-regexp 
  440.     (concat "@\\("
  441.         (mapconcat 'car texinfo-section-list "\\>\\|")
  442.         "\\>\\)"))
  443.   (make-local-variable 'outline-level)
  444.   (setq outline-level 'texinfo-outline-level)
  445.   (make-local-variable 'tex-start-of-header)
  446.   (setq tex-start-of-header "%**start")
  447.   (make-local-variable 'tex-end-of-header)
  448.   (setq tex-end-of-header "%**end")
  449.   (run-hooks 'text-mode-hook 'texinfo-mode-hook))
  450.  
  451.  
  452. ;;; Insert string commands
  453.  
  454. (defconst texinfo-environment-regexp
  455.   "^[ \t]*@\\(f?table\\|enumerate\\|itemize\
  456. \\|ifhtml\\|ifinfo\\|iftex\\|ifset\\|ifclear\
  457. \\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display\\|format\
  458. \\|flushleft\\|flushright\\|ignore\\|group\\|tex\\|html\\|cartouche\\|menu\
  459. \\|titlepage\\|end\\|def[a-z]*[a-wyz]\\>\\)"
  460.   "Regexp for environment-like Texinfo list commands.
  461. Subexpression 1 is what goes into the corresponding `@end' statement.")
  462.  
  463. (defun texinfo-insert-@end ()
  464.   "Insert the matching `@end' for the last Texinfo command that needs one."
  465.   (interactive)
  466.   (let ((depth 1) string)
  467.     (save-excursion
  468.       (while (and (> depth 0)
  469.           (re-search-backward texinfo-environment-regexp nil t)
  470.     (if (looking-at "@end")
  471.         (setq depth (1+ depth))
  472.       (setq depth (1- depth)))))
  473.       (looking-at texinfo-environment-regexp)
  474.       (if (zerop depth)
  475.       (setq string
  476.         (buffer-substring (match-beginning 1)
  477.                   (match-end 1)))))
  478.     (insert "@end ")
  479.     (if string (insert string "\n"))))
  480.  
  481. ;; The following insert commands accept a prefix arg N, which is the
  482. ;; number of words (actually s-exprs) that should be surrounded by
  483. ;; braces.  Thus you can first paste a variable name into a .texinfo
  484. ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
  485. ;; pasted variable name to put @var{...} *around* the variable name.
  486. ;; Operate on previous word or words with negative arg.
  487.  
  488. ;; These commands use texinfo-insert-@-with-arg
  489. (defun texinfo-insert-@-with-arg (string &optional arg)
  490.   (if arg 
  491.       (progn
  492.         (setq arg (prefix-numeric-value arg))
  493.         (if (< arg 0)
  494.             (progn
  495.               (skip-chars-backward " \t\n\r\f")
  496.               (save-excursion
  497.                 (forward-sexp arg)
  498.                 (insert "@" string "{"))
  499.               (insert "}"))
  500.           (skip-chars-forward " \t\n\r\f")
  501.           (insert "@" string "{")
  502.           (forward-sexp arg)
  503.           (insert "}")))
  504.     (insert "@" string "{}")
  505.     (backward-char)))
  506.  
  507. (defun texinfo-insert-braces ()
  508.   "Make a pair of braces and be poised to type inside of them.
  509. Use \\[up-list] to move forward out of the braces."
  510.   (interactive)
  511.   (insert "{}")
  512.   (backward-char))
  513.  
  514. (defun texinfo-insert-@code (&optional arg)
  515.   "Insert a `@code{...}' command in a Texinfo buffer.
  516. A numeric argument says how many words the braces should surround.
  517. The default is not to surround any existing words with the braces."
  518.   (interactive "P")
  519.   (texinfo-insert-@-with-arg "code" arg))
  520.  
  521. (defun texinfo-insert-@dfn (&optional arg)
  522.   "Insert a `@dfn{...}' command in a Texinfo buffer.
  523. A numeric argument says how many words the braces should surround.
  524. The default is not to surround any existing words with the braces."
  525.   (interactive "P")
  526.   (texinfo-insert-@-with-arg "dfn" arg))
  527.  
  528. (defun texinfo-insert-@example ()
  529.   "Insert the string `@example' in a Texinfo buffer."
  530.   (interactive)
  531.   (insert "@example\n"))
  532.  
  533. (defun texinfo-insert-@file (&optional arg)
  534.   "Insert a `@file{...}' command in a Texinfo buffer.
  535. A numeric argument says how many words the braces should surround.
  536. The default is not to surround any existing words with the braces."
  537.   (interactive "P")
  538.   (texinfo-insert-@-with-arg "file" arg))
  539.  
  540. (defun texinfo-insert-@item ()
  541.   "Insert the string `@item' in a Texinfo buffer."
  542.   (interactive)
  543.   (insert "@item")
  544.   (newline))
  545.  
  546. (defun texinfo-insert-@kbd (&optional arg)
  547.   "Insert a `@kbd{...}' command in a Texinfo buffer.
  548. A numeric argument says how many words the braces should surround.
  549. The default is not to surround any existing words with the braces."
  550.   (interactive "P")
  551.   (texinfo-insert-@-with-arg "kbd" arg))
  552.  
  553. (defun texinfo-insert-@node ()
  554.   "Insert the string `@node' in a Texinfo buffer.
  555. This also inserts on the following line a comment indicating
  556. the order of arguments to @node."
  557.   (interactive)
  558.   (insert "@node \n@comment  node-name,  next,  previous,  up")
  559.   (forward-line -1)
  560.   (forward-char 6))
  561.  
  562. (defun texinfo-insert-@noindent ()
  563.   "Insert the string `@noindent' in a Texinfo buffer."
  564.   (interactive)
  565.   (insert "@noindent\n"))
  566.  
  567. (defun texinfo-insert-@samp (&optional arg)
  568.   "Insert a `@samp{...}' command in a Texinfo buffer.
  569. A numeric argument says how many words the braces should surround.
  570. The default is not to surround any existing words with the braces."
  571.   (interactive "P")
  572.   (texinfo-insert-@-with-arg "samp" arg))
  573.  
  574. (defun texinfo-insert-@table (&optional arg)
  575.   "Insert the string `@table' in a Texinfo buffer."
  576.   (interactive "P")
  577.   (insert "@table "))
  578.  
  579. (defun texinfo-insert-@var (&optional arg)
  580.   "Insert a `@var{}' command in a Texinfo buffer.
  581. A numeric argument says how many words the braces should surround.
  582. The default is not to surround any existing words with the braces."
  583.   (interactive "P")
  584.   (texinfo-insert-@-with-arg "var" arg))
  585.  
  586. ;;; Texinfo file structure
  587.  
  588. ;; These are defined in tenfo-upd.el.
  589. (defvar texinfo-section-types-regexp)
  590. (defvar texinfo-section-level-regexp)
  591. (defvar texinfo-subsection-level-regexp)
  592. (defvar texinfo-subsubsection-level-regexp)
  593.  
  594. (defun texinfo-show-structure (&optional nodes-too) 
  595.   "Show the structure of a Texinfo file.
  596. List the lines in the file that begin with the @-sign commands for
  597. @chapter, @section, and the like.
  598.  
  599. With optional argument (prefix if interactive), list both the lines
  600. with @-sign commands for @chapter, @section, and the like, and list
  601. @node lines.
  602.  
  603. Lines with structuring commands beginning in them are displayed in
  604. another buffer named `*Occur*'.  In that buffer, you can move point to
  605. one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence], 
  606. to jump to the corresponding spot in the Texinfo source file."
  607.  
  608.   (interactive "P")
  609.   (require 'texnfo-upd)
  610.   (save-excursion 
  611.     (goto-char (point-min))
  612.     (if nodes-too
  613.         (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
  614.       (occur texinfo-section-types-regexp)))
  615.   (pop-to-buffer "*Occur*")
  616.   (goto-char (point-min))
  617.   (flush-lines "-----")
  618.   ;; Now format the "*Occur*" buffer to show the structure.
  619.   ;; Thanks to ceder@signum.se (Per Cederqvist)
  620.   (goto-char (point-max))
  621.   (let ((margin 5))
  622.     (while (re-search-backward "^ *[0-9]*:" nil 0)
  623.       (re-search-forward ":")
  624.       (setq margin
  625.             (cond
  626.              ((looking-at
  627.                (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
  628.              ;; ((looking-at "@chapter ") 5)
  629.              ;; ((looking-at "@unnumbered ") 5)
  630.              ;; ((looking-at "@appendix ") 5)
  631.              ;; ((looking-at "@majorheading ") 5)
  632.              ;; ((looking-at "@chapheading ") 5)
  633.  
  634.              ((looking-at
  635.                (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
  636.              ;; ((looking-at "@section ") 9)
  637.              ;; ((looking-at "@unnumberedsec ") 9)
  638.              ;; ((looking-at "@appendixsec ") 9)
  639.              ;; ((looking-at "@heading ") 9)
  640.  
  641.              ((looking-at 
  642.                (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
  643.              ;; ((looking-at "@subsection ") 13)
  644.              ;; ((looking-at "@unnumberedsubsec ") 13)
  645.              ;; ((looking-at "@appendixsubsec ") 13)
  646.              ;; ((looking-at "@subheading ") 13)
  647.  
  648.              ((looking-at 
  649.                (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
  650.              ;; ((looking-at "@subsubsection ") 17)
  651.              ;; ((looking-at "@unnumberedsubsubsec ") 17)
  652.              ;; ((looking-at "@appendixsubsubsec ") 17)
  653.              ;; ((looking-at "@subsubheading ") 17)
  654.              (t margin)))
  655.       (indent-to-column margin)
  656.       (beginning-of-line))))
  657.  
  658. ;;; The  tex  and  print  function definitions:
  659.  
  660. (defvar texinfo-texi2dvi-command "texi2dvi"
  661.   "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer.")
  662.  
  663. (defvar texinfo-tex-command "tex"
  664.   "*Command used by `texinfo-tex-region' to run TeX on a region.")
  665.  
  666. (defvar texinfo-texindex-command "texindex"
  667.   "*Command used by `texinfo-texindex' to sort unsorted index files.")
  668.  
  669. (defvar texinfo-delete-from-print-queue-command "lprm"
  670.   "*Command string used to delete a job from the line printer queue.
  671. Command is used by \\[texinfo-delete-from-print-queue] based on
  672. number provided by a previous \\[tex-show-print-queue]
  673. command.")
  674.  
  675. (defvar texinfo-tex-trailer "@bye"
  676.   "String appended after a region sent to TeX by `texinfo-tex-region'.")
  677.  
  678. (defun texinfo-tex-region (beg end)
  679.   "Run TeX on the current region.
  680. This works by writing a temporary file (`tex-zap-file') in the directory
  681. that is the value of `tex-directory', then running TeX on that file.
  682.  
  683. The first line of the buffer is copied to the
  684. temporary file; and if the buffer has a header, it is written to the
  685. temporary file before the region itself.  The buffer's header is all lines
  686. between the strings defined by `tex-start-of-header' and `tex-end-of-header'
  687. inclusive.  The header must start in the first 100 lines.
  688.  
  689. The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
  690.   (interactive "r")
  691.   (require 'tex-mode)
  692.   (if (get-buffer "*tex-shell*")
  693.       (tex-kill-job)
  694.     (tex-start-shell))
  695.   (or tex-zap-file (setq tex-zap-file (make-temp-name "#tz")))
  696.   (let ((tex-out-file (concat tex-zap-file ".tex"))
  697.     (temp-buffer (get-buffer-create " tex-Output-Buffer"))
  698.     (zap-directory
  699.          (file-name-as-directory (expand-file-name tex-directory))))
  700.     (save-excursion
  701.       (save-restriction
  702.     (widen)
  703.     (goto-char (point-min))
  704.     (forward-line 100)
  705.     (let ((search-end (point))
  706.           (hbeg (point-min)) (hend (point-min))
  707.           (default-directory zap-directory))
  708.       (goto-char (point-min))
  709.           
  710.           ;; Copy first line, the `\input texinfo' line, to temp file
  711.       (write-region (point) 
  712.                         (save-excursion (end-of-line) (point))
  713.                         tex-out-file nil nil)
  714.           
  715.           ;; Don't copy first line twice if region includes it.
  716.           (forward-line 1)
  717.           (if (< beg (point)) (setq beg (point)))
  718.           
  719.           ;; Initialize the temp file with either the header or nothing
  720.           (if (search-forward tex-start-of-header search-end t)
  721.               (progn
  722.                 (beginning-of-line)
  723.                 (setq hbeg (point))    ; Mark beginning of header.
  724.                 (if (search-forward tex-end-of-header nil t)
  725.                     (progn (beginning-of-line)
  726.                            (setq hend (point)))    ; Mark end of header.
  727.                   (setq hbeg (point-min))))) ; Else no header.
  728.           
  729.           ;; Copy  header  to temp file.
  730.           (write-region (min hbeg beg) hend tex-out-file t nil)
  731.           
  732.           ;; Copy  region  to temp file.
  733.           (write-region (max beg hend) end tex-out-file t nil))
  734.         
  735.         ;; This is  a kludge to insert the tex-trailer into the tex-out-file.
  736.         ;;  We have to create a special buffer in which to insert
  737.         ;;  the tex-trailer first because there is no function with
  738.         ;;  which to append a literal string directly to a file.
  739.         (let ((local-tex-trailer texinfo-tex-trailer))
  740.           (set-buffer temp-buffer)
  741.           (erase-buffer)
  742.           ;; make sure trailer isn't hidden by a comment
  743.           (insert-string "\n")
  744.           (if local-tex-trailer (insert-string local-tex-trailer))
  745.           (tex-set-buffer-directory temp-buffer zap-directory)
  746.           (write-region (point-min) (point-max) tex-out-file t nil))
  747.  
  748. ;;; The following is sufficient in Emacs 19.
  749. ;;;    (write-region (concat "\n" texinfo-tex-trailer) nil
  750. ;;;              tex-out-file t nil)
  751.     ))
  752.     
  753.     (tex-set-buffer-directory "*tex-shell*" zap-directory)
  754.     (tex-send-command tex-shell-cd-command zap-directory)
  755.     (tex-send-command texinfo-tex-command tex-out-file))
  756.   (tex-recenter-output-buffer 0))
  757.  
  758. (defun texinfo-tex-buffer ()
  759.   "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
  760.   (interactive)
  761.  
  762.   ;; Make sure TeX shell is running.
  763.   (require 'tex-mode)
  764.   (if (get-buffer "*tex-shell*")
  765.       (quit-process (get-process "tex-shell") t)
  766.     (tex-start-shell))
  767.  
  768.   (cond ((null buffer-file-name)
  769.          (error "Buffer not visiting any file!"))
  770.         ((buffer-modified-p)
  771.          (error "Buffer has been modified since last saved!")))
  772.  
  773.   (setq tex-zap-file buffer-file-name)
  774.  
  775.   (tex-send-command tex-shell-cd-command (file-name-directory tex-zap-file))
  776.  
  777.   (tex-send-command texinfo-texi2dvi-command tex-zap-file)
  778.  
  779.   (tex-recenter-output-buffer 0))
  780.  
  781. (defun texinfo-texindex ()
  782.   "Run `texindex' on unsorted index files.
  783. The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  784. This runs the shell command defined by `texinfo-texindex-command'."
  785.   (interactive)
  786.   (require 'tex-mode)
  787.   (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
  788.   (tex-recenter-output-buffer nil))
  789.  
  790. (defun texinfo-tex-print ()
  791.   "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  792. This runs the shell command defined by `tex-dvi-print-command'."
  793.   (interactive)
  794.   (require 'tex-mode)
  795.   (tex-send-command tex-dvi-print-command (concat tex-zap-file ".dvi"))
  796.   (tex-recenter-output-buffer nil))
  797.  
  798. (defun texinfo-quit-job ()
  799.   "Quit currently running TeX job, by sending an `x' to it."
  800.   (interactive)
  801.   (if (not (get-process "tex-shell"))
  802.       (error "No TeX shell running"))
  803.   (tex-send-command "x"))
  804.  
  805. (defun texinfo-delete-from-print-queue (job-number)
  806.   "Delete job from the line printer spooling queue.
  807. You are prompted for the job number (use a number shown by a previous
  808. \\[texinfo-show-print-queue] command)."
  809.   (interactive "nPrinter job number for deletion: ")
  810.   (require 'tex-mode)
  811.   (if (tex-shell-running)
  812.       (tex-kill-job)
  813.     (tex-start-shell))
  814.   (tex-send-command texinfo-delete-from-print-queue-command job-number)
  815.   (tex-recenter-output-buffer nil))
  816.  
  817. (provide 'texinfo)
  818.  
  819. ;;; texinfo.el ends here
  820.